from com.power.auto.test.maven.maven_push import *
from com.power.auto.test.job.Job import *


class JobFlow(object):
    job_flow = []

    def __init__(self, flow_file_name):
        self.flow_file_name = flow_file_name

    def ini_hessian_flow(self):
        # 1.读取配置，是否需要动态自动加载facade和common包
        if EnvManager.get_maven_init() == MavenInitConfig.OPEN.name:
            init_maven()
        env = EnvManager.get_env()
        hessian_config = parse_yml(
            EnvManager.get_config_path() + '/' + self.flow_file_name + '-' + env.lower() + '.yml')
        i = 1

        while hessian_config['job'].__contains__('p' + str(i)):
            key = 'p' + str(i)
            jobitem = hessian_config['job'][key]
            print(jobitem)
            i = i + 1
            url = hessian_config['base-url'] + jobitem['url-suf']
            class_name = jobitem['class_name']
            method = jobitem['invoke_methond']
            param_class = jobitem['param_class']
            param_json = jobitem['param_json']
            print('解析出的%s接口数据class=%s,methond=%s,param_class=%s,params_son=%s,url=%s' % (
                key, class_name, method, param_class, param_json, url))
            self.job_flow.append(
                Job(str(url), str(class_name), str(method), str(param_class), str(param_json)))



    def invoke(self):
        result = None
        if len(self.job_flow) > 0:
            for job in self.job_flow:
                if (result is None):
                    pass
                else:
                    pass
                result = job.invok();
            print('调用%s接口返回结果%s' % (job.invoke_methode, result))

        else:
            print('未配置任何工作流!')
